package com.bc004346.travelus.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.bc004346.travelus.R;
import com.bc004346.travelus.SettingsActivity;
import com.bc004346.travelus.TripMeDestinationsActivity;
import com.bc004346.travelus.utility.Utility;

/**
 * Created by Renats on 12/5/2014.
 * Trip me disclaimer with an option to setup home base
 */
public class TripMeDisclaimerFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        @SuppressLint("InflateParams")
        View v = inflater.inflate(R.layout.fragment_trip_me_disclaimer, null);
        final EditText homeBase = (EditText) v.findViewById(R.id.fragment_trip_me_disclaimer_home_base);
        Button next = (Button) v.findViewById(R.id.fragment_trip_me_disclaimer_next);
        Button cancel = (Button) v.findViewById(R.id.fragment_trip_me_disclaimer_cancel);

        next.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String aaa = homeBase.getText() != null ? homeBase.getText().toString() : "";
                if (aaa.length() != 3) {
                    Toast.makeText(getActivity(), "Please provide a valid 3 character home base", Toast.LENGTH_SHORT).show();
                    return;
                }

                Utility.showTripMeDisclaimer = false;
                Utility.onStop(getActivity());
                SettingsActivity.setHomeBase(getActivity().getApplicationContext(), aaa.toUpperCase());
                startActivity(new Intent(getActivity(), TripMeDestinationsActivity.class));
                getActivity().finish();
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        return v;
    }
}
